
attribute vec3		va_Tangent1;
attribute vec3		va_Tangent2;

uniform vec3		viewOrigin;			// Passed in automatically
uniform mat3		entityAxis;			// Passed in automatically

varying vec3		viewVector;
varying vec2		bumpTexCoord;
varying mat3		tangentToGlobal;
varying vec4		vertexColor;


void main (void){

	vec3		viewVec;

	// Position invariant
	gl_Position = ftransform();

	// Compute the view vector in tangent space
	viewVec = viewOrigin - gl_Vertex.xyz;

	viewVector.x = dot(viewVec, va_Tangent1);
	viewVector.y = dot(viewVec, va_Tangent2);
	viewVector.z = dot(viewVec, gl_Normal);

	// Copy the bump map texcoord
	bumpTexCoord = gl_MultiTexCoord0.st;

	// Compute the tangent-to-global transformation matrix
	tangentToGlobal[0].x = dot(va_Tangent1, entityAxis[0]);
	tangentToGlobal[1].x = dot(va_Tangent1, entityAxis[1]);
	tangentToGlobal[2].x = dot(va_Tangent1, entityAxis[2]);

	tangentToGlobal[0].y = dot(va_Tangent2, entityAxis[0]);
	tangentToGlobal[1].y = dot(va_Tangent2, entityAxis[1]);
	tangentToGlobal[2].y = dot(va_Tangent2, entityAxis[2]);

	tangentToGlobal[0].z = dot(gl_Normal, entityAxis[0]);
	tangentToGlobal[1].z = dot(gl_Normal, entityAxis[1]);
	tangentToGlobal[2].z = dot(gl_Normal, entityAxis[2]);

	// Copy the vertex color
	vertexColor = gl_Color;
}
